package tjs.study.notes.eureka.clienta.user.service.feign.log;

import feign.RequestInterceptor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.MDC;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class FeignInterceptorConfig {
    @Bean
    public RequestInterceptor requestInterceptor() {
        RequestInterceptor requestInterceptor = template -> {
            System.out.println(CommonConstant.TL.get());
            //传递日志traceId
            String traceId = (String) MDC.get(CommonConstant.LOG_TRACE_ID);
            if (StringUtils.isNotEmpty(traceId)) {
                template.header(CommonConstant.LOG_TRACE_ID, traceId);
            }
        };
        return requestInterceptor;
    }
}